<!-- 订单购买页 -->
<template>
  <div>
    <section>
    <van-list
      v-model="loading"
      :finished="finished"
      @load="onLoad"
      loading-text="正在加载..."
    >
    <template v-for="item in list">
      <van-card @click="goGoods(item);"
        :price="item.nowPrice"
        :desc="item.buyNum+'人参与'"
        :title="item.title"
        :thumb="item.picName.indexOf('http')!=-1?item.picName:downloadUrl+'?fileName='+item.picName"
      >
        <div slot="footer">
          <div style="display: flex;justify-content: flex-end;">
            <div class="kh_pic" @click.stop="goGoods(item);">{{item.integral}}积分兑换</div>
          </div>

          <!--<van-button size="mini" type="danger">购买</van-button>-->
        </div>
      </van-card>
    </template>
    </van-list>

    <div class="weui-loadmore weui-loadmore_line" v-if="finished && list.length!=0 && page>1">
      <span class="weui-loadmore__tips">{{loadMsg}}</span>
    </div>

      <template v-if="finished && list.length==0">
        <div class="error-info">
          <div>
            <img src="../../assets/img/yiyenodata.png"/>
          </div>
          <div class="error">您还没有可兑换的商品哟~</div>
        </div>

      </template>

  </section>

    <div class="back-home" @click="goHome();">
      <div>返回</div>
      <div>首页</div>
    </div>

  </div>
</template>
<script>
  import goodsService from '../../api/goodsService';
  import util from '../../../../../static/mobile/js/util';
  import Api from '../../api/api';
  import {Dialog} from 'vant';
  import reCharge from '../commonComponents/reCharge';
  export default {
    name:'index',
    components: {
      reCharge
    },
    data() {
      return {
        amount:'',
        showRecharge:false,
        isAuth:'',
        isWeixin:false,
        downloadUrl:Api.download,
        active:'home',
        datalist: [],
        list: [],
        loading: false,
        finished: false,
        loadMsg: '暂无数据',
        totalPage: '',
        page: 1
      }
    },
    methods: {
      goHome() {
        var url = window.location.origin + window.location.pathname+'?vt='+new Date().getTime() + '#/index?auth=1';
        window.location.href = url;
      },
      goGoods(item) {
        this.$nocacheRouter('/goodsDetailGet?id='+item.id+'&isJf=1');
      },
      goUrl(url) {
        this.$nocacheRouter(url);
      },
      _resetList() {
        this.finished = true;
        this.$nextTick(function(){
          this.page = 1;
          this.loading = false;
          this.finished = false;
          this.datalist = [];
          this.list = [];
        });

      },

      onLoad() {
        var that = this;
        if(this.timer) {
          clearTimeout(this.timer);
        }
        this.timer = setTimeout(() => {
          that.getList();
      }, CONSTANT.LIST_TIMEOUT);
      },
      getList() {
        goodsService.goodsListByGrade({currPage:this.page,pageSize:10,isJf:1}).then((rsp)=>{
          if(rsp.result) {
          this.loading = false;
          this.list = this.list.concat(rsp.obj.goodsList);
          var totalPage = rsp.obj.totalPage;
          if ((this.page + 1) > totalPage) {
            this.finished = true;
            this.loadMsg = '我是有底线的';
          }else {
            this.page = this.page + 1;
          }
        }else {
          this.$toast(rsp.errorMsg);
        }
      }).catch((error)=>{
          this.$toast('goodsListByGrade接口异常'+error);
      });
      },
    },

    mounted(){
    }
  };
</script>
<style scoped>

  .error-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 1.50rem;
    text-align: center;
  }

  .error-info img{
    width: 2.85rem;
    height: 2.85rem;
  }

  .error-info .error {
    margin-top: 0.40rem;
    font-size: 0.30rem;
    color: #999;
  }

  .error-info .error div{
    font-size: 0.40rem;
  }

</style>

<style>
  .van-icon {
    display: block;
    font-size: 24px;
  }
  .van-tabbar-item--active{
    color: #f44;
  }

  .van-card__thumb {
    width: 120px;
    height: 120px;
  }

  .van-card__title {
    font-size: 14px;
  }

  .van-card__bottom {
    font-size: 16px;
  }

  .van-card__desc {
    margin-top: 15px;
  }

  .kh_pic {
    font-size: 14px;
    color: #fff;
    border-radius: 3px;
    background: linear-gradient(to right, #fb7d7d, #F44);
    height: 0.64rem;
    line-height: 0.64rem;
    text-align: center;
    width: 2.4rem;
    box-sizing: border-box;
    margin-bottom: 10px;
  }

  .van-card {
    background: #fff;
  }
</style>
